<?php

class Kim_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = 'set_kim';
        $this->load->model("functions_model");
    }

    function update($editted_by,$kim_council, $board_of_fellows,$kim_comitees) {
        $data = $_POST;
        if($kim_council) {
            $data['kim_council'] = $kim_council;
        }
        if($board_of_fellows) {
            $data['board_of_fellows'] = $board_of_fellows;
        }
        if($kim_comitees) {
            $data['kim_comitees'] = $kim_comitees;
        }
        // var_dump($data);
        //exit;
        $data['editted_by'] = $editted_by;
        $data['last_editted'] = $this->functions_model->nowDateTime();
        $this->db->update($this->tableName, $data);
    }

    function incrementHitCount() {
        $hits = $this->getHitCount() + 1;
        $data['hit_count'] = $hits;
        $this->db->update($this->tableName, $data);
    }

    function getHitCount() {
        $this->db->select("hit_count");
        $query = $this->db->get($this->tableName);
        $row = $query->row();
        return $row->hit_count;
    }

    function getAll($NL2BR=TRUE) {
        $this->db->from($this->tableName);
        $query = $this->db->get();
        $result = array();
        $row = $query->row_array();
        $row['last_editted'] = $this->functions_model->prettyDateTime($row['last_editted']);
        if ($NL2BR) {
            $row["mision"] = nl2br($row["mision"]);
            $row["vision"] = nl2br($row["vision"]);
            $row["core_values"] = nl2br($row["core_values"]);
        }
        if(strlen(str_replace(" ","",$row["kim_council"]))>0) {
            $row["kim_council"] = "<a href=" . base_url() . "uploads/" . $row['kim_council'] . ">Download</a>";
        }
        if(strlen(str_replace(" ","",$row["board_of_fellows"]))>0) {
        $row["board_of_fellows"] = "<a href=" . base_url() . "uploads/" . $row['board_of_fellows'] . ">Download</a>";
        }

        if(strlen(str_replace(" ","",$row["kim_comitees"]))>0) {
        $row["kim_comitees"] = "<a href=" . base_url() . "uploads/" . $row['kim_comitees'] . ">Download</a>";
        }
        return $row;
    }

}

?>
